/*
 * Copyright (C) RT, 2017 by kiterunner_t
 * TO THE HAPPY FEW
 */

package com.zgys.mes.common.config;

import java.util.concurrent.atomic.AtomicBoolean;

import com.zgys.mes.util.error.RtErrorEnum;
import com.zgys.mes.util.error.RtException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import com.zgys.mes.util.Log;

@Aspect
@Component
public class StartInterceptor {
    private AtomicBoolean init = new AtomicBoolean(false);


    @Before("execution(* com.rt.mes.rest.*.*(..)) && "
        + "@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void controllerPointCut(JoinPoint jp) {
        init();
    }


    public void setInit() {
        init.compareAndSet(false, true);
    }


    private void init() {
        if (!init.get()) {
            Log.warn("系统初始化还未完成，禁止访问。");
            throw new RtException(RtErrorEnum.ERROR_BAD_REQUEST);
        }
    }
}

